package com.atguigu.InternetCoding;

import org.junit.Test;

import java.io.IOException;
import java.net.*;

/**
 * @author xiaoqi
 * @data 2021/04/27 11:25
 */
public class UDPClient {
    @Test
    public void Client() throws IOException {
        //建立一个UDP对象,可以不填写端口号，但接收的一端必须开放端口号
        DatagramSocket socket = new DatagramSocket(9099);
        //设置数据报
        String str = "这是UDP连接端";
        DatagramPacket packet = new DatagramPacket(str.getBytes(),0,str.getBytes().length,InetAddress.getByName("localhost"),9999);
        //发送数据
        socket.send(packet);
        socket.close();
    }
}
